package com.msstudio;

// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 

import com.msstudio.utils.PkgTools;
import com.msstudio.utils.HttpPosterListener;
import com.msstudio.midlets.MSCMIDlet;
import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;

public class MainForm extends TimerTask
    implements HttpPosterListener
{

    private Timer sysTimer;
    private int iTimerCnt;
    private boolean updatedStat;
    public boolean iFirstTimeQuery;
    private boolean iStartGetFriendTimer;
    private int iLogoutCnt;

    public MainForm()
    {
        sysTimer = null;
        iTimerCnt = 0;
        updatedStat = false;
        iFirstTimeQuery = true;
        iStartGetFriendTimer = false;
        iLogoutCnt = 0;
    }

    public void init()
    {
    }

    public void show()
    {
        MSCMIDlet.display.setCurrent(MSCMIDlet.friendList);
        MSCMIDlet.friendList.startTimer();
    }

    public Displayable GetWindow()
    {
        return MSCMIDlet.friendList;
    }

    public void StopQQ()
    {
        if(iLogoutCnt == 0)
            iLogoutCnt = 1;
        else
            MSCMIDlet.instance.quitApp();
    }

    public void startSysTimer()
    {
        if(sysTimer == null)
        {
            sysTimer = new Timer();
            sysTimer.schedule(this, 500L, 500L);
        }
    }

    public void stopSysTimer()
    {
        if(sysTimer != null)
        {
            sysTimer.cancel();
            sysTimer = null;
        }
    }

    public void startTimer()
    {
        if(!iStartGetFriendTimer)
        {
            iTimerCnt = 0;
            iStartGetFriendTimer = true;
        }
    }

    public void stopTimer()
    {
        iStartGetFriendTimer = false;
        updatedStat = false;
    }

    public void run()
    {
        if(iLogoutCnt != 0)
        {
            if(++iLogoutCnt > 30)
                MSCMIDlet.instance.quitApp();
            return;
        }
        iTimerCnt++;
        MSCMIDlet.instance.OnTimer();
        MSCMIDlet.friendList.OnTimer();
        //MSCMIDlet.httpPoster.OnTimer();
        if(iTimerCnt % 30 == 0)
            MSCMIDlet.getMsgDlg.OnTimer();
        if(iTimerCnt % 10 == 0)
            MSCMIDlet.friendRecord.OnTimer();
        if(iStartGetFriendTimer)
        {
            char c;
            if(updatedStat)
                c = '\u0168';
            else
                c = 'x';
            if(iTimerCnt >= c)
            {
                iTimerCnt = 0;
                MSCMIDlet.httpPoster.getFriend(this);
            }
        }
    }

    public void updateStat(String s, String s1)
    {
        MSCMIDlet.friendRecord.updateStat(s, s1);
        MSCMIDlet.friendList.buildFriendList();
    }

    public void receiveHttpResponse(String s)
    {
        String s1;
        String s2;
        s1 = PkgTools.GetParaVal("CMD", s).toUpperCase();
        s2 = PkgTools.GetParaVal("RES", s);
        String s6;
        String s8;
        String s9;
        int k1;
        String as1[];
        int i = 0;
        if(!s1.equals("QUERY_STAT") || !s2.equals("0")) {
            return;
        }
        updatedStat = true;
        String s3 = PkgTools.GetParaVal("SN", s);
        String s5 = PkgTools.GetParaVal("UN", s);
        s6 = PkgTools.GetParaVal("FC", s);
        s8 = PkgTools.GetParaVal("ST", s);
        s9 = PkgTools.GetParaVal("NK", s);
        k1 = Integer.parseInt(s3);
        if(k1 <= 0) {
            return;
        }
        as1 = new String[k1];
        i = PkgTools.GetMultiPara(as1, s5);
        if(k1 != i)
            return;
        String as2[];
        as2 = new String[k1];
        int j = PkgTools.GetMultiPara(as2, s6);
        if(k1 != j)
            return;
        String as3[];
        as3 = new String[k1];
        int k = PkgTools.GetMultiPara(as3, s9);
        if(k1 != k)
            return;
        String as4[];
        as4 = new String[k1];
        int l = PkgTools.GetMultiPara(as4, s8);
        if(k1 != l)
            return;
        if(MSCMIDlet.friendRecord.updateOnlineRecord(as1, as3, as2, as4) < 0)
            return;
        if(iFirstTimeQuery)
        {
            iFirstTimeQuery = false;
            MSCMIDlet.friendRecord.loadFriendInfor();
        }
        MSCMIDlet.getMsgDlg.startTimer();
        //break MISSING_BLOCK_LABEL_386;
        if(!s1.equals("LIST") || !s2.equals("0")) {
            //break MISSING_BLOCK_LABEL_386;
            return;
        }
        if(!MSCMIDlet.instance.isWaitLogin)
            return;
        String as[];
        String s4 = PkgTools.GetParaVal("SN", s);
        int j1 = Integer.parseInt(s4);
        MSCMIDlet.friendRecord.iTotleFriendNum = j1;
        if(j1 <= 0) {
            //break MISSING_BLOCK_LABEL_336;
            return;
        }
        String s7 = PkgTools.GetParaVal("UN", s);
        as = new String[j1];
        int i1 = PkgTools.GetMultiPara(as, s7);
        if(j1 != i1)
            return;
        if(MSCMIDlet.friendRecord.buildRecord(as) < 0)
            return;
        try
        {
            if(iFirstTimeQuery)
                MSCMIDlet.friendList.buildFriendList();
            MSCMIDlet.instance.onLoadEnd();
            MSCMIDlet.httpPoster.getFriend(this);
            startTimer();
        }
        catch(NumberFormatException numberformatexception) { }
        catch(Exception exception)
        {
            MSCMIDlet.instance.handleHttpError(null);
        }
    }

    public void handleHttpError(String s)
    {
        MSCMIDlet.instance.handleHttpError(null);
    }
}
